package com.chf.job.service.impl;

import com.chf.job.dao.ResumeMapper;
import com.chf.job.pojo.Resume;
import com.chf.job.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ResumeServiceImpl implements ResumeService {
    @Autowired
    private ResumeMapper resumeMapper;

    /**
     * 根据邮箱查询用户基本信息
     * @param email
     * @return
     */
    @Override
    public Resume getUserBaseInfo(String email) {
        return resumeMapper.getUserBaseInfo(email);
    }

    /**
     * 添加简历
     * @param email
     * @return
     */
    @Override
    public int addResume(String email) {
        Resume resume = new Resume();
        resume.setEmail(email);
        return resumeMapper.insertSelective(resume);
    }

    /**
     * 更新简历名称
     * @param email
     * @param newResumeName
     * @return
     */
    @Override
    public int updateResumeName(String email, String newResumeName) {
        return resumeMapper.updateByEmail(email, newResumeName);
    }

    /**
     * 跟新简历基本信息
     * @param resume
     * @return
     */
    @Override
    public int updateBaseInfo(Resume resume) {
        // 同时跟新用户基本信息
        Resume newResume = new Resume();
        newResume.setId(resume.getId());
        newResume.setUserName(resume.getUserName());
        newResume.setUserGender(resume.getUserGender());
        newResume.setEduBack(resume.getEduBack());
        newResume.setProjectExpe(resume.getProjectExpe());
        newResume.setUserPhone(resume.getUserPhone());
        newResume.setEmail(resume.getEmail());
        newResume.setNowStatus(resume.getNowStatus());
        return resumeMapper.updateByPrimaryKeySelective(newResume);
    }

    /**
     * 更新自我描述
     * @param resume
     * @return
     */
    @Override
    public int updateMyDescription(Resume resume) {
        Resume newResume = new Resume();
        newResume.setId(resume.getId());
        newResume.setMyDesc(resume.getMyDesc());
        return resumeMapper.updateByPrimaryKeySelective(newResume);
    }

    /**
     * 删除我的自我描述
     * 实际是不可删除的，只需要把他设置成空即可
     * @param resumeId
     * @return
     */
    @Override
    public int updateMyDesc(Integer resumeId) {
        Resume resume = new Resume();
        resume.setId(resumeId);
        resume.setMyDesc("");
        return resumeMapper.updateByPrimaryKeySelective(resume);
    }

    /**
     * 上传简历头像
     * @param email
     * @param path
     * @return
     */
    @Override
    public int updateHeardImg(String email, String path) {
        return resumeMapper.updateHeardImg(email, path);
    }



}
